<template>
	<el-dialog title="AT命令配置" v-model="visible" :close-on-click-modal="false" draggable width="660px">
		<el-form :model="form" ref="dataFormRef" label-width="150px" :rules="dataRules">
			<el-form-item label="配置命令：" prop="commond">
				<el-input type="textarea" v-model="form.commond" :autosize="{ minRows: 4, maxRows: 8 }" placeholder="请输入" />
			</el-form-item>
		</el-form>
		<div class="flex mt-[30px]">
			<div class="min-w-[150px] flex items-center">
				<el-icon color="#E6A23C" size="16" class="mr-1"> <Warning /> </el-icon> 单个配置命令示例：
			</div>
			<div class="text-danger">AT+DEBUG=2</div>
		</div>
		<div class="flex my-2">
			<div class="min-w-[150px] flex items-center">
				<el-icon color="#E6A23C" size="16" class="mr-1"> <Warning /> </el-icon> 多个配置命令示例：
			</div>
			<div class="text-danger">AT+DEBUG=2;AT+SIMNO=18565423025（注：多命令要用分号隔开）</div>
		</div>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="visible = false">取消</el-button>
				<el-button type="primary" @click="onSubmit" :disabled="loading">确认</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { useMessage } from '/@/hooks/message';
const emit = defineEmits(['refresh']);
const visible = ref(false);
const loading = ref(false);
const dataFormRef = ref();
const form = reactive({
	commond: '',
});
// 打开弹窗
const openDialog = (id: string) => {
	visible.value = true;
	console.log(id);
};
const dataRules = ref({
	commond: [{ required: true, message: '请输入', trigger: 'blur' }],
});

// 提交
const onSubmit = async () => {
	const valid = await dataFormRef.value.validate().catch(() => {});
	if (!valid) return false;
	try {
		loading.value = true;
		// form.id ? await putObj(form) : await addObj(form);
		// useMessage().success(form.id ? '修改成功' : '添加成功');
		visible.value = false;
		emit('refresh');
	} catch (err: any) {
		useMessage().error(err.msg);
	} finally {
		loading.value = false;
	}
};
// 暴露变量
defineExpose({
	openDialog,
});
</script>

<style lang="scss" scoped></style>
